
//
//  HomeVideoCell.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/25.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "HomeVideoCell.h"
#import "HomeVideoTool.h"

@interface HomeVideoCell ()
@property(nonatomic, strong)UIImageView *videoView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)HomeVideoTool *toolView;
@end

@implementation HomeVideoCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString * identifier = @"HomeVideoCell";
    HomeVideoCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[HomeVideoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        self.videoView = [[UIImageView alloc] init];
        self.videoView.backgroundColor = [UIColor xm_grayColor];
        [self addSubview:self.videoView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.font = [UIFont xm_medium:15.0];
        self.titleLabel.numberOfLines = 0;
        self.titleLabel.textColor = [UIColor xm_colorFromRGB:0xFFFFFF];
        [self.videoView addSubview:self.titleLabel];
        
        self.toolView = [[HomeVideoTool alloc] init];
        [self addSubview:self.toolView];
        
    }
    return self;
}


-(void)setModel:(AticleModel *)model{
    _model = model;
    
    [self.videoView xm_setImageWithURL:_model.ImgUrl placeholderImage:nil];
    self.titleLabel.text = _model.Title;
    self.toolView.model = _model;
}



-(void)layoutSubviews{
    [super layoutSubviews];
    [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(self);
        make.height.mas_equalTo(self.width * (9.0/16));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.videoView).offset(15);
        make.right.mas_equalTo(self.videoView).offset(-15);
        make.top.mas_equalTo(self.videoView).offset(13);
    }];
    [self.toolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self.videoView.mas_bottom);
    }];
}


@end
